/**
 * 
 */
package com.example.countandbuy;

import android.database.sqlite.SQLiteDatabase;
import android.content.Context;
import android.database.Cursor;
import android.content.ContentValues;

/**
 * @author Jens
 *
 */
public class CountAndBuyDatenbank extends android.database.sqlite.SQLiteOpenHelper {
	private static final String DATENBANK_NAME = "countandbuy.db";
	private static final int DATENBANK_VERSION = 1;
	private SQLiteDatabase db;
	
	public CountAndBuyDatenbank(Context context) {
	  super( context, DATENBANK_NAME, null, DATENBANK_VERSION);
	  db = getWritableDatabase();
	}
	
	public void onCreate(SQLiteDatabase db) {
	  db.execSQL("CREATE TABLE INVENTUREN (_id INTEGER PRIMARY KEY AUTOINCREMENT, start varchar(20) not null, ende varchar(20), erfasser varchar(20), lagerort varchar(20), Fixiert varchar(1))");
	  ContentValues daten = new ContentValues();
	  daten.put("start", "20120101");
	  daten.put("ende", "20130101");
	  daten.put("erfasser", "Max");
	  db.insert("INVENTUREN", null, daten );
	}
	
	public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion) {
	db.execSQL("DROP TABLE INVENTUREN");
	onCreate(db);
	}
	
	public Cursor erzeugeListViewCursor() {
		String[] spalten = new String[]{"_id", "start", "ende", "erfasser","lagerort"};
		return db.query("INVENTUREN", spalten, null, null, null, null, "_id");
	}
	
}
